<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex flex-direction flex-wrap align-stretch benben-position-layout flex messageData_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center justify-between flex-sub messageData_fd0_0'>
          <image class='messageData_fd0_0_c1' mode="aspectFit" @tap.stop="handleJumpDiy" data-type="navigateTo"
            :data-url="`/pages/shouye/search/search`" :src='STATIC_URL+"23.png"'></image>

          </image>
          <text class='messageData_fd0_0_c0'>消息</text>
          <image class='messageData_fd0_0_c1' mode="aspectFit" src='/static/tab/tab_diy2.png' @tap.stop="isedit=!isedit"
            data-type="navigateTo" :data-url="`/pages/tabBar/releasePage/releasePage`">
        </view>

      </view>
      <view class="mask-fiii" v-if="isedit" :style="{top: (90+StatusBarRpx)+'rpx'}">
        <view class='flex flex-direction align-stretch benben-flex-position-popup flex favoritePosts_popup_1'>
          <text class='favoritePosts_positionPopup1_c0 ' @tap.stop="gopublishFunc(1)">发个帖</text>
          <text class=' favoritePosts_positionPopup1_c0 ' @tap.stop="gopublishFunc(2)">提个问</text>
          <text class='favoritePosts_positionPopup1_c0s' @tap.stop="gopublishFunc(3)">组个局</text>
          <!-- <text class='favoritePosts_positionPopup1_c2' @tap.stop="delFunc()">删除收藏夹</text> -->
        </view>
      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout messageData_flex_1">
        <view class='flex flex-wrap align-center justify-between messageData_fd1_0'>
          <view class='flex flex-direction flex-wrap align-center' @tap.stop="handleJumpDiy" data-type="navigateTo"
            :data-url="`/pages/xiaoxi/commentPage/commentPage`">
            <view class='messageData_fd1_0_c0_c0'>
              <image class='messageData_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"31.png"'></image>
              <benben-message-num class='messagesPage_fd1_0_c0_c1' size='25' color='#fff' background-color='red'
                :message-num="info.comment_choose">
              </benben-message-num>
            </view>
            <text class='messageData_fd1_0_c0_c1'>评论和@</text>
          </view>
          <view class='flex flex-direction flex-wrap align-center' @tap.stop="handleJumpDiy" data-type="navigateTo"
            :data-url="`/pages/xiaoxi/praiseandCollection/praiseandCollection`">
            <view class='messageData_fd1_0_c0_c0'>
              <image class='messageData_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"33.png"'></image>
              <benben-message-num class='messagesPage_fd1_0_c0_c1' size='25' color='#fff' background-color='red'
                :message-num="info.suppert_collection">
              </benben-message-num>
            </view>
            <!-- <image class='messageData_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"33.png"'></image> -->
            <text class='messageData_fd1_0_c0_c1'>赞和收藏</text>
          </view>
          <view class='flex flex-direction flex-wrap align-center' @tap.stop="handleJumpDiy" data-type="navigateTo"
            :data-url="`/pages/xiaoxi/addFollow/addFollow`">
            <view class='messageData_fd1_0_c0_c0'>
              <image class='messageData_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"32.png"'></image>
              <benben-message-num class='messagesPage_fd1_0_c0_c1' size='25' color='#fff' background-color='red'
                :message-num="info.follow">
              </benben-message-num>
            </view>
            <!-- <image class='messageData_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_sURL+"32.png"'></image> -->
            <text class='messageData_fd1_0_c0_c1'>新增关注</text>
          </view>
        </view>
      </view>

      <!---flex布局flex布局结束-->
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout messageData_flex_2">

        <view class='flex flex-wrap align-start messageData_fd2_0' @tap.stop="handleJumpDiy" data-type="navigateTo"
          :data-url="`/pages/xiaoxi/platformAnnouncement/platformAnnouncement`">
          <view class='messageData_fd1_0_c0_c0'>
            <image class='messageData_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"34.png"'></image>
            <benben-message-num class='messagesPage_fd1_0_c0_c1' size='25' color='#fff' background-color='red'
              :message-num="info.system">
            </benben-message-num>
          </view>
          <!--   <view class="messageData_fd3_0">
            <image class='messageData_fd3_0_c0' mode="aspectFit" :src='STATIC_URL+"34.png"'></image>
            <benben-message-num class='messagesPage_fd1_0_c0_c1' size='20' color='#fff' background-color='red'
              :message-num="info.system">
            </benben-message-num>
          </view> -->

          <view class='flex flex-direction flex-wrap align-stretch flex-sub messageData_fd2_0_c1'>
            <view class='flex flex-wrap align-center justify-between'>
              <text class='messageData_fd2_0_c1_c0_c0'>系统消息</text>
              <text class='messageData_fd2_0_c1_c0_c1'>{{info.news_system_time}}</text>
            </view>
            <view class='flex flex-wrap align-center messageData_fd2_0_c1_c1'>
              <text class='messageData_fd2_0_c1_c1_c0'>{{info.news_system}}</text>
              <image class='messageData_fd2_0_c1_c1_c1' v-if="false" mode="aspectFit" :src='STATIC_URL+"35.png"'>
              </image>
            </view>
          </view>
        </view>

      </view>

      <!---flex布局flex布局结束-->
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout messageData_flex_3">
        <view class='flex flex-wrap align-start messageData_fd3_0' v-for="(item,index) in listinfo" :key="index"
          @click.stop="gochat(item)">
          <view class='messageData_fd1_0_c0_c0' style="margin-right: 14rpx;">
            <image class='messageData_fd1_0_c0_c0' mode="aspectFill" :src='item.userProfile.avatar'></image>
            <benben-message-num class='messagesPage_fd1_0_c0_c1' size='25' color='#fff' background-color='red'
              :message-num="item.unreadCount">
            </benben-message-num>
          </view>
          <view class='flex flex-direction flex-wrap align-stretch flex-sub messageData_fd3_0_c1'>
            <view class='flex flex-wrap align-center justify-between'>
              <text class='messageData_fd3_0_c1_c0_c0'>{{item.userProfile.nick}}</text>
              <text
                class='messageData_fd3_0_c1_c0_c1'>{{$util.timeFormat(item.lastMessage.lastTime,'mm-dd h:M')}}</text>
            </view>
            <view class='flex flex-wrap align-center messageData_fd3_0_c1_c1'>
              <text class='messageData_fd3_0_c1_c1_c0'>{{item.lastMessage.messageForShow}}</text>
            </view>
          </view>
        </view>
      </view>

      <!---flex布局flex布局结束-->
      <benben-popup v-model="popupShow1705070444859" :mask="true" :mask-close-able="false" mode='center' :z-index='999'>
        <!---没有验证flex布局开始-->
        <view class="flex benben-flex-layout flex-wrap align-center">
          <view class='flex flex-direction flex-wrap align-center releasePage_fd1_0'>
            <text class='releasePage_fd1_0_c0'>提示</text>
            <text class='releasePage_fd1_0_c1'>您的学校还没有验证通过，暂不
              能发布，是否去进项学校验证？</text>
            <view class='flex align-center releasePage_fd1_0_c2'>
              <button class='releasePage_fd1_0_c2_c0' @tap.stop="popupShow1705070444859=false">取消</button>
              <button class='releasePage_fd1_0_c2_c1' @tap.stop="handleJumpDiy" data-type="navigateTo"
                :data-url="`/pages/dlzc/addSchool/addSchool`">去验证</button>
            </view>
          </view>
        </view>

        <!---没有验证flex布局结束-->

      </benben-popup>

    </view>
  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js';
  import {
    TUILogin
  } from "@tencentcloud/tui-core";
  import {
    SYSTEM_CONFIG,
    SDKAppID,
    secretKey
  } from "@/common/config.js";
  import {
    TUIChatKit,
    genTestUserSig
  } from "@/TUIKit";
  import {
    vueVersion
  } from "@/TUIKit/adapter-vue";
  import TencentCloudChat from '@tencentcloud/chat';
  import {
    TUIConversationService
  } from '@tencentcloud/chat-uikit-engine';
  export default {
    components: {},


    data() {
      return {
        info: {
          comment_choose: 0,
          follow: 0,
          suppert_collection: 0,
          news_system_time: '',
          news_system: ''
        },
        listinfo: [],
        chatnums: 0,
        // listData: []
        isedit: false,
        data: '',
        popupShow1705070444859: false
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },
      isLogin() {
        return this.$store.state.token == '' ? false : true;
      },
      userInfo: {
        get() {
          return this.$store.state.userInfo.userinfo
        },
        set() {
          this.$store.commit('updateUserInfo', value)
        },
      },
    },
    watch: {},
    onLoad(options) {

    },
    onUnload() {
      uni.$TUIKit.off(uni.$TUIKitEvent.SDK_READY, this.onConversationListUpdated);
    },
    onReady() {
      console.log('isLogin', this.isLogin)
    },
    onShow() {
      if (this.isLogin) {
        const userID = this.userInfo ? this.userInfo.id.toString() : '';
        let config = {
          userID: userID, //User ID
          SDKAppID: SDKAppID, // Your SDKAppID
          secretKey: secretKey, // Your secretKey
        }
        const userSig = genTestUserSig(config).userSig;
        TUILogin.login({
          SDKAppID: config.SDKAppID,
          userID: config.userID,
          userSig: userSig,
          // 如果您需要发送图片、语音、视频、文件等富媒体消息，请设置为 true
          useUploadPlugin: true,
          useProfanityFilterPlugin: false,
          framework: `vue${vueVersion}` // 当前开发使用框架 vue2 / vue3
        }).then(() => {
          console.log('index登录成功1111')
          this.getMessFunc()
          this.list()
          // this.timer = setInterval(res => {

          // }, 3000)
        })
      }

    },
    onHide() {
      this.isedit = false
      this.popupShow1705070444859 = false
    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      async getUserFunc() {
        //请求方法
        //数据验证

        let datadata = await this.$api.get(global.apiUrls.post5c78c4772da97, {

        });

        if (datadata.data.code != 1) {
          this.$message.info(datadata.data.msg);
          return
        }
        let infodata = datadata.data;
        this.data = infodata.data
      },
      gopublishFunc(type) {
        if (this.data.is_school == 0 || this.data.is_school == 1) {
          this.popupShow1705070444859 = true;
        } else {
          if (type == '1') {
            this.$urouter.navigateTo(`/pages/fabu/postApost/postApost?aid=0&type=1`);
          } else if (type == '2') {
            this.$urouter.navigateTo(`/pages/fabu/postApost/postApost?aid=0&type=2`);
          } else if (type == '3') {
            this.$urouter.navigateTo(`/pages/fabu/groupBureau/groupBureau?aid=0`);
          }
        }
      },
      // 聊天
      gochat(item) {
        console.log('iii', item)
        TUIConversationService.switchConversation(`C2C${item.userProfile.userID}`)
        uni.navigateTo({
          url: "/TUIKit/components/TUIChat/index"
        })
      },
      list() {
        let that = this
        if (uni.$TIM.isReady()) {
          clearInterval(this.timer)
          let promise = TUILogin.chat.getConversationList();
          promise.then(function(imResponse) {
            console.log(imResponse.data.conversationList, 27);
            that.listinfo = imResponse.data.conversationList

            let userIDList = []
            that.listinfo.map((item, index) => {
              userIDList.push(item.userProfile.userID)
              let promise = TUILogin.chat.getUserProfile({
                userIDList // 请注意：即使只拉取一个用户的资料，也需要用数组类型，例如：userIDList: ['user1']
              });
              promise.then(function(imResponse) {

                that.listinfo[index].userProfile.birthday = imResponse.data[index]
                  .birthday
                that.listinfo[index].userProfile.gender = imResponse.data[index]
                  .gender

                console.log(imResponse.data, 191, that
                  .listinfo); // 存储用户资料的数组 - [Profile]
              }).catch(function(imError) {
                console.warn('getUserProfile error:', imError); // 获取其他用户资料失败的相关信息
              });
            })
            console.log('listinlistinfolistinfolistinfofo', that.listinfo)
            // const conversationList = imResponse.data.conversationList; // 全量的会话列表，用该列表覆盖原有的会话列表
            // const isSyncCompleted = imResponse.data.isSyncCompleted; // 从云端同步会话列表是否完成
          }).catch(function(imError) {
            console.warn('getConversationList error:', imError); // 获取会话列表失败的相关信息
          });
        }

      },
      // enddddddddd
      //获取消息
      async getMessFunc() {
        //请求方法
        //数据验证

        let datadataMeas = await this.$api.get(global.apiUrls.post657a9b8d16d9b, {

        });

        if (datadataMeas.data.code != 1) {
          this.$message.info(datadataMeas.data.msg);
          return
        }
        let infodataMeas = datadataMeas.data;
        this.info = infodataMeas.data
        if (uni.$TIM.isReady()) {
          this.chatnums = TUILogin.chat.getTotalUnreadMessageCount();
          // this.$store.commit('getNum', nums);

        }
        let totaoNum = parseFloat(this.chatnums) + parseFloat(this.info.total)
        if (totaoNum) {
          uni.setTabBarBadge({
            index: 2,
            text: totaoNum.toString()
          })
        } else {
          uni.removeTabBarBadge({
            index: 2
          })
        }

        console.log('dataMeas', this.info)

      }
    }
  };
</script>
<style lang="scss" scoped>
  .releasePage_fd1_0_c2_c1 {
    background: rgba(255, 255, 255, 1);
    font-size: 32rpx;
    color: rgba(100, 80, 235, 1);
    width: 270rpx;
    height: 101rpx;
    line-height: 101rpx;
    font-weight: 500;
  }

  .releasePage_fd1_0_c2_c0 {
    border-right: 1px solid #eee;
    background: #fff;
    font-size: 32rpx;
    color: rgba(153, 153, 153, 1);
    width: 270rpx;
    height: 101rpx;
    line-height: 101rpx;
    font-weight: 400;
  }

  .releasePage_fd1_0_c2 {
    border-top: 1px solid #eee;
    margin: 51rpx 0rpx 0rpx 0rpx;
  }

  .releasePage_fd1_0_c1 {
    line-height: 44rpx;
    font-size: 28rpx;
    font-weight: 500;
    color: #333333;
    text-align: center;
    margin: 32rpx 40rpx 0rpx 40rpx;
  }

  .releasePage_fd1_0_c0 {
    line-height: 44rpx;
    font-size: 36rpx;
    font-weight: 700;
    color: #333333;
    margin: 40rpx 0rpx 0rpx 0rpx;
  }

  .releasePage_fd1_0 {
    background: #fff;
    width: 540rpx;
    background-size: 100% auto !important;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
  }

  .mask-fiii {
    width: auto;
    position: fixed;
    // top: 100rpx;
    right: 32rpx;
    z-index: 99;
  }

  .favoritePosts_popup_1 {
    background: rgba(51, 51, 51, 1);
    border-radius: 8rpx 8rpx 8rpx 8rpx;
    width: 245rpx;
    height: 264rpx;
    background-size: 100% auto !important;
  }



  .favoritePosts_positionPopup1_c0s {
    text-align: center;
    line-height: 38rpx;
    color: #FFFFFF;
    font-size: 28rpx;
    font-weight: 400;
    padding: 24rpx 0rpx 24rpx 0rpx;
  }

  .favoritePosts_positionPopup1_c0 {
    border-bottom: 1rpx solid rgba(112, 112, 112, 1);
    text-align: center;
    line-height: 38rpx;
    color: #FFFFFF;
    font-size: 28rpx;
    font-weight: 400;
    padding: 24rpx 0rpx 24rpx 0rpx;
  }

  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: rgba(255, 255, 255, 1);
    background-size: 100% auto;
  }

  .messageData_flex_0 {
    background: rgba(255, 255, 255, 1);
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto;
  }

  .messageData_fd0_0_c1 {
    width: 44rpx;
    height: 44rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .messageData_fd0_0_c0 {
    color: #333333;
    font-size: 40rpx;
    font-weight: 700;
    line-height: 45rpx;
  }

  .messageData_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .messageData_flex_1 {
    background: rgba(255, 255, 255, 1);
    background-size: 100% auto;
  }

  .messageData_fd1_0_c0_c1 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 32rpx;
    margin: 20rpx 0rpx 0rpx 0rpx;
  }

  .messageData_fd1_0_c0_c0 {
    width: 104rpx;
    height: 104rpx;
    border-radius: 50%;
    position: relative;

    image {
      width: 100%;
      height: 100%
    }
  }

  // absolute
  .messagesPage_fd1_0_c0_c1 {
    position: absolute;
    top: 0;
    right: 0
  }

  .messageData_fd1_0 {
    padding: 40rpx 72rpx 40rpx 72rpx;
  }

  .messageData_flex_2 {
    border-top: 20px solid rgba(248, 248, 248, 1);
    background: rgba(255, 255, 255, 1);
    background-size: 100% auto;
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .messageData_fd2_0_c1_c1_c1 {
    width: 20rpx;
    height: 20rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 0rpx 0rpx auto;
  }

  .messageData_fd2_0_c1_c1_c0 {
    color: #999999;
    font-size: 24rpx;
    font-weight: 400;
    line-height: 32rpx;
    -webkit-line-clamp: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    width: 525rpx;
  }

  .messageData_fd2_0_c1_c1 {
    margin: 16rpx 0rpx 0rpx 0rpx;
  }

  .messageData_fd2_0_c1_c0_c1 {
    color: #BFBFBF;
    font-size: 24rpx;
    font-weight: 400;
    line-height: 56rpx;
  }

  .messageData_fd2_0_c1_c0_c0 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 500;
    line-height: 32rpx;
  }

  .messageData_fd2_0_c1 {
    border-bottom: 1px solid #eee;
    padding: 0rpx 0rpx 33rpx 24rpx;
  }

  .messageData_fd2_0_c0 {
    width: 90rpx;
    height: 90rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 24rpx 0rpx 0rpx;
  }

  .messageData_fd2_0 {
    margin: 32rpx 0rpx 0rpx 0rpx;
  }

  .messageData_flex_3 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .messageData_fd3_0_c1_c1_c0 {
    color: #999999;
    font-size: 24rpx;
    font-weight: 400;
    line-height: 32rpx;
    -webkit-line-clamp: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    width: 525rpx;
  }

  .messageData_fd3_0_c1_c1 {
    margin: 16rpx 0rpx 0rpx 0rpx;
  }

  .messageData_fd3_0_c1_c0_c1 {
    color: #BFBFBF;
    font-size: 24rpx;
    font-weight: 400;
    line-height: 56rpx;
  }

  .messageData_fd3_0_c1_c0_c0 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 500;
    line-height: 32rpx;
  }

  .messageData_fd3_0_c1 {
    border-bottom: 1px solid #eee;
    padding: 0rpx 0rpx 33rpx 0rpx;
  }

  .messageData_fd3_0_c0 {
    width: 90rpx;
    height: 90rpx;
    border-radius: 50%;
    margin: 0rpx 24rpx 0rpx 0rpx;
  }

  .messageData_fd3_0 {
    margin: 32rpx 0rpx 0rpx 0rpx;
  }
</style>
